<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>子传父案例2</title>
    <script src="lib/vue.js"></script>
</head>

<body>
    <div id="box">
        <navbar @myevent="handleEvent"></navbar>
        <sidebar v-show="isShow"></sidebar>

    </div>

    <script>
        //子组件
        //navbar
        Vue.component("navbar", {
            template: `<div>
                navbar
                <button @click="handleClick">navbar-button</button>
                </div>`,
            methods: {
                handleClick() {
                    this.$emit("myevent")
                }
            }
        })
        //sidebar
        Vue.component("sidebar", {
            template: `<div style="background:yellow;width:200px;">
                <ul>
                    <li>11111</li>
                    <li>22222</li>
                    <li>33333</li>
                </ul>
                </div>`
        })

        new Vue({
            el: "#box",
            data: {
                isShow: true
            },
            methods: {
                handleEvent() {
                    this.isShow = !this.isShow
                }
            }
        })
    </script>

</body>

</html>